package cn.wwcyc.controller;

import cn.wwcyc.domain.*;
import cn.wwcyc.mapper.TjYjXxMapper;
import cn.wwcyc.service.TjDwService;
import cn.wwcyc.service.TjGxService;
import cn.wwcyc.service.TjYjXxService;
import cn.wwcyc.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
//@SpringBootApplication
//@MapperScan("cn.wwcyc.mapper")
@RestController
@RequestMapping("/yjxx")
public class YjXxController {
    @Autowired
    UserService userService;
    @Autowired
    TjDwService tjDwService;
    @Autowired
    TjYjXxMapper yjxxMapper;
    @Autowired
    TjYjXxService yjxxService;
    @Autowired
    TjGxService gxService;

    @RequestMapping("/getpageBydwgxjh")
    public R<IPage<TjYjXxVo>> getPageBydwgxjh(
            @RequestParam Integer pagenum,
            @RequestParam Integer pagesize,
            @RequestParam(required = false) String jh,
            @RequestParam(required = false) Long dw,
            @RequestParam(required = false) Long gx,
            HttpServletRequest request
    ) {

        QueryWrapper<TjYjXx> qw = new QueryWrapper<>();
        if (!StringUtils.isBlank(jh)) {
            qw.like("jh", jh);
        }

        User user = userService.getCurrentUser(request);
        if (dw == null)
            dw = user.getDw();

        TjDw tjDw = null;
        if (dw != null) {
            tjDw = tjDwService.getDwTreeById(dw);
        }
        List<TjDw> dwlist = new ArrayList<>();
        dwlist = tjDwService.DwTreeToList(dwlist, tjDw);
        List<Long> dwIdList = new ArrayList<>();
        for (TjDw tjDw1 : dwlist) {
            dwIdList.add(tjDw1.getId());
        }
        if (gx != null) {
            qw.eq("gx", gx);
        }
        if (dwIdList.size() > 0) {
            qw.in("dw", dwIdList);
        }
        long count = yjxxMapper.selectCount(qw);

        IPage<TjYjXxVo> page = new Page<>(pagenum, pagesize);
        page.setTotal(count);
        page.setPages(page.getTotal() % page.getSize() == 0 ? page.getTotal() / page.getSize() : page.getTotal() / page.getSize() + 1);
        if (pagenum > page.getPages()) {
            page.setCurrent(page.getPages());
        }
        if (pagenum < 1) {
            page.setCurrent(1);
        }
//        System.out.println("pagenum:" + pagenum + "  pagesize:" + pagesize + " current:" + page.getCurrent() + "  size:" + page.getSize() + " pages:" + page.getPages());
        List<TjYjXxVo> list = yjxxMapper.selectPagewithdwgxBydwgxjh(page.getCurrent(), page.getSize(), jh, dwIdList, gx);
        page.setRecords(list);
        return R.success(page);
    }

    @RequestMapping("/getjhsBydw")
    public R<List<String>> getJhsBydw(@RequestParam Long dwid){
        List<Long> dwIdlist = tjDwService.getSelfAndDescendantIdList(dwid);
        QueryWrapper<TjYjXx> queryWrapper = new QueryWrapper();
        queryWrapper.in("dw", dwIdlist);
        List<TjYjXx> yjXxList = yjxxMapper.selectList(queryWrapper);
        List<String> jhs = new ArrayList<>();
        for (TjYjXx yjxx : yjXxList) {
            jhs.add(yjxx.getJh());
        }
        return R.success(jhs);
    }

    @RequestMapping("/getDwByJh")
    public R<Long> getDwByJh(@RequestParam String jh) {
        QueryWrapper<TjYjXx> qw = new QueryWrapper();
        qw.eq("jh", jh);
        TjYjXx yjxx = yjxxMapper.selectOne(qw);
        return R.success(yjxx.getDw());
    }

    @PostMapping("/save")
    public R save(@RequestBody TjYjXx yjxx) {
        yjxxService.transsave(yjxx);
        return R.success();
    }

    @PostMapping("/edit")
    public R edit(@RequestBody TjYjXx yjxx) {
//        yjxxService.updateById(yjxx);
        yjxxService.transedit(yjxx);
        return R.success();
    }

    @DeleteMapping
    public R del(Long id) {
        yjxxService.transremoveById(id);
        return R.success();
    }

    @PostMapping("delbatch")
    public R delbatch(@RequestBody List<TjYjXx> yjXxList) {
        yjxxService.transRemoveBatch(yjXxList);
        return R.success();
    }

    @PostMapping("/import")
    public R batchImport(@RequestParam MultipartFile file) throws IOException {
        System.out.println("batchImport  called");
        int successCount = 0;
        int errCount = 0;
        String errmsg = "";
        String originFileName = file.getOriginalFilename();
        Long size = file.getSize();
        XSSFWorkbook workbook = null;
        InputStream inputStream = null;
        try {
            inputStream = file.getInputStream();
            workbook = new XSSFWorkbook(inputStream);
            Sheet sheet = workbook.getSheetAt(0); // 获取第一个工作表
            //获取根单位
            QueryWrapper queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("dwname", "文卫采油厂");
            TjDw root = tjDwService.getOne(queryWrapper);
            root = tjDwService.getDwTreeById((long) root.getId());
            List<TjDw> dwList = new ArrayList<>();
            dwList = tjDwService.DwTreeToList(dwList, root);//所有单位列表
            List<TjGx> gxList = gxService.list();//所有干线列表
            int rowCount = sheet.getLastRowNum() - sheet.getFirstRowNum() + 1;
            for (int i = 1; i < rowCount; i++) {
                try {
                    Row row = sheet.getRow(i);
//            int columnCount = row.getLastCellNum() - row.getFirstCellNum();
//            for (int j = 0; j < columnCount; j++) {
//                Cell cell = row.getCell(j);
//                System.out.print(cell.toString() + "\t");
//            }
//            System.out.println();
                    Long dwL = null;
                    Long gxL = null;
                    String jh = row.getCell(0).toString().trim();
                    if (jh == null || jh.equals("")) {
//                System.out.println("+++++____________+");
                        continue;
                    }
                    String ip = null;
                    String dw = null;
                    String gx = null;
                    if(row.getCell(1)!=null) {
                        ip = row.getCell(1).toString().trim();
                    }
                    if(row.getCell(2)!=null) {
                        dw = row.getCell(2).toString().trim();
                    }
                    if(row.getCell(3)!=null) {
                        gx = row.getCell(3).toString().trim();
                    }
//                    String dw = row.getCell(2).toString().trim();
//                    String gx = row.getCell(3).toString().trim();
                    for (TjDw dwfor : dwList) {
                        System.out.println("danwei sql:" + dwfor + "    dw excel: " + dw);
                        if (dwfor.getDwname().equals(dw)) {
                            dwL = dwfor.getId();
                        }
                    }
                    for (TjGx gxfor : gxList) {
                        if (gxfor.getName().equals(gx)) {
                            gxL = gxfor.getId();
                        }
                    }
                    TjYjXx yjXx = new TjYjXx();
                    yjXx.setJh(jh);//井号
                    yjXx.setDw(dwL);//单位
                    yjXx.setGx(gxL);//干线
                    yjXx.setIp(ip);//ip
                    if (row.getCell(4) != null) {
                        try {
                            Long tjloc = Long.parseLong(row.getCell(4).toString().trim());//停机位
                            yjXx.setCyjtjloc(tjloc);
                        } catch (Exception e) {
                        }
                    }
                    if (row.getCell(5) != null) {
                        try {
                            Long tjflag = Long.parseLong(row.getCell(5).toString().trim());//停机flag
                            yjXx.setCyjtjflag(tjflag);
                        } catch (Exception e) {
                        }
                    }
                    //回压寄存器
                    if (row.getCell(6) != null) {
                        if (row.getCell(6).toString().trim().equals("保持寄存器")) {
                            yjXx.setHyregtype(4L);
                        } else if (row.getCell(6).toString().trim().equals("输入寄存器")) {
                            yjXx.setHyregtype(3L);
                        }
                    }
                    if (row.getCell(7) != null) {
                        try {
//                            Long hyloc = Long.parseLong(row.getCell(7).toString().trim());
                            Double d = row.getCell(7).getNumericCellValue();
                            Long l = d.longValue();
                            yjXx.setHyloc(l);
                        } catch (Exception e) {
                        }
                    }
                    if (row.getCell(8) != null) {

                        if (row.getCell(8).toString().trim().equals("16位无符号数")) {
                            yjXx.setHydatatype(2L);
                        } else if (row.getCell(8).toString().trim().equals("16位整数")) {
                            yjXx.setHydatatype(3L);
                        } else if (row.getCell(8).toString().trim().equals("32位无符号数")) {
                            yjXx.setHydatatype(4L);
                        } else if (row.getCell(8).toString().trim().equals("32位整数")) {
                            yjXx.setHydatatype(5L);
                        } else if (row.getCell(8).toString().trim().equals("32位float")) {
                            yjXx.setHydatatype(8L);
                        }

                    }
                    if (row.getCell(9) != null) {

                        if (row.getCell(9).toString().trim().equals("0.01d")) {
                            yjXx.setHybh(1L);
                        } else if (row.getCell(9).toString().trim().equals("无变换")) {
                            yjXx.setHybh(2L);
                        } else if (row.getCell(9).toString().trim().equals("含水率")) {
                            yjXx.setHybh(3L);
                        }

                    }
                    //套压寄存器
                    if (row.getCell(10) != null) {

                        if (row.getCell(10).toString().trim().equals("保持寄存器")) {
                            yjXx.setTyregtype(4L);
                        } else if (row.getCell(10).toString().trim().equals("输入寄存器")) {
                            yjXx.setTyregtype(3L);
                        }

                    }
                    if (row.getCell(11) != null) {
                        try {
//                            Long tyloc = Long.parseLong(row.getCell(11).toString().trim());
                            Double d = row.getCell(11).getNumericCellValue();
                            Long l = d.longValue();
                            yjXx.setTyloc(l);
                        } catch (Exception e) {
                        }
                    }
                    if (row.getCell(12) != null) {
                        if (row.getCell(12).toString().trim().equals("16位无符号数")) {
                            yjXx.setTydatatype(2L);
                        } else if (row.getCell(12).toString().trim().equals("16位整数")) {
                            yjXx.setTydatatype(3L);
                        } else if (row.getCell(12).toString().trim().equals("32位无符号数")) {
                            yjXx.setTydatatype(4L);
                        } else if (row.getCell(12).toString().trim().equals("32位整数")) {
                            yjXx.setTydatatype(5L);
                        } else if (row.getCell(12).toString().trim().equals("32位float")) {
                            yjXx.setTydatatype(8L);
                        }
                    }
                    if (row.getCell(13) != null) {
                        if (row.getCell(13).toString().trim().equals("0.01d")) {
                            yjXx.setTybh(1L);
                        } else if (row.getCell(13).toString().trim().equals("无变换")) {
                            yjXx.setTybh(2L);
                        } else if (row.getCell(13).toString().trim().equals("含水率")) {
                            yjXx.setTybh(3L);
                        }
                    }
                    //温度寄存器
                    if (row.getCell(14) != null) {
                        if (row.getCell(14).toString().trim().equals("保持寄存器")) {
                            yjXx.setWdregtype(4L);
                        } else if (row.getCell(14).toString().trim().equals("输入寄存器")) {
                            yjXx.setWdregtype(3L);
                        }
                    }
                    if (row.getCell(15) != null) {
                        try {
                            Double d = row.getCell(15).getNumericCellValue();
                            Long l = d.longValue();
//                            Long wdloc = Long.parseLong(row.getCell(15).toString().trim());
                            yjXx.setWdloc(l);
                        } catch (Exception e) {
                        }
                    }
                    if (row.getCell(16) != null) {
                        if (row.getCell(16).toString().trim().equals("16位无符号数")) {
                            yjXx.setWddatatype(2L);
                        } else if (row.getCell(16).toString().trim().equals("16位整数")) {
                            yjXx.setWddatatype(3L);
                        } else if (row.getCell(16).toString().trim().equals("32位无符号数")) {
                            yjXx.setWddatatype(4L);
                        } else if (row.getCell(16).toString().trim().equals("32位整数")) {
                            yjXx.setWddatatype(5L);
                        } else if (row.getCell(16).toString().trim().equals("32位float")) {
                            yjXx.setWddatatype(8L);
                        }
                    }
                    if (row.getCell(17) != null) {
                        if (row.getCell(17).toString().trim().equals("0.01d")) {
                            yjXx.setWdbh(1L);
                        } else if (row.getCell(17).toString().trim().equals("无变换")) {
                            yjXx.setWdbh(2L);
                        } else if (row.getCell(17).toString().trim().equals("含水率")) {
                            yjXx.setWdbh(3L);
                        }
                    }
                    //含水寄存器
                    if (row.getCell(18) != null) {
                        if (row.getCell(18).toString().trim().equals("保持寄存器")) {
                            yjXx.setHsregtype(4L);
                        } else if (row.getCell(18).toString().trim().equals("输入寄存器")) {
                            yjXx.setHsregtype(3L);
                        }
                    }
                    if (row.getCell(19) != null) {
                        try {
//                            Long hsloc = Long.parseLong(row.getCell(19).toString().trim());
                            Double d = row.getCell(19).getNumericCellValue();
                            Long l = d.longValue();
                            yjXx.setHsloc(l);
                        } catch (Exception e) {
                        }
                    }
                    if (row.getCell(20) != null) {
                        if (row.getCell(20).toString().trim().equals("16位无符号数")) {
                            yjXx.setHsdatatype(2L);
                        } else if (row.getCell(20).toString().trim().equals("16位整数")) {
                            yjXx.setHsdatatype(3L);
                        } else if (row.getCell(20).toString().trim().equals("32位无符号数")) {
                            yjXx.setHsdatatype(4L);
                        } else if (row.getCell(20).toString().trim().equals("32位整数")) {
                            yjXx.setHsdatatype(5L);
                        } else if (row.getCell(20).toString().trim().equals("32位float")) {
                            yjXx.setHsdatatype(8L);
                        }
                    }
                    if (row.getCell(21) != null) {
                        if (row.getCell(21).toString().trim().equals("0.01d")) {
                            yjXx.setHsbh(1L);
                        } else if (row.getCell(21).toString().trim().equals("无变换")) {
                            yjXx.setHsbh(2L);
                        } else if (row.getCell(21).toString().trim().equals("含水率")) {
                            yjXx.setHsbh(3L);
                        }
                    }
                    //加药罐液位
                    if (row.getCell(22) != null) {
                        if (row.getCell(22).toString().trim().equals("保持寄存器")) {
                            yjXx.setJygywregtype(4L);
                        } else if (row.getCell(22).toString().trim().equals("输入寄存器")) {
                            yjXx.setJygywregtype(3L);
                        }
                    }
                    if (row.getCell(23) != null) {
                        try {
                            Double d = row.getCell(23).getNumericCellValue();
                            Long jygywloc = d.longValue();
                            yjXx.setJygywloc(jygywloc);
                        } catch (Exception e) {
                            System.out.println("加药罐液位地址转换异常"+ e.getMessage());
                        }
                    }
                    if (row.getCell(24) != null) {
                        if (row.getCell(24).toString().trim().equals("16位无符号数")) {
                            yjXx.setJygywdatatype(2L);
                        } else if (row.getCell(24).toString().trim().equals("16位整数")) {
                            yjXx.setJygywdatatype(3L);
                        } else if (row.getCell(24).toString().trim().equals("32位无符号数")) {
                            yjXx.setJygywdatatype(4L);
                        } else if (row.getCell(24).toString().trim().equals("32位整数")) {
                            yjXx.setJygywdatatype(5L);
                        } else if (row.getCell(24).toString().trim().equals("32位float")) {
                            yjXx.setJygywdatatype(8L);
                        }
                    }
                    if (row.getCell(25) != null) {
                        if (row.getCell(25).toString().trim().equals("0.01d")) {
                            yjXx.setJygywbh(1L);
                        } else if (row.getCell(25).toString().trim().equals("无变换")) {
                            yjXx.setJygywbh(2L);
                        } else if (row.getCell(25).toString().trim().equals("含水率")) {
                            yjXx.setJygywbh(3L);
                        }
                    }
                    System.out.println("11111111111111111111111");
                    System.out.println(yjXx);

                    yjxxService.transsave(yjXx);
                    successCount++;
                } catch (Exception e) {
                    System.out.println("============" + e.getMessage());
                    Row row = sheet.getRow(i);
                    String jh = row.getCell(0).toString().trim();
                    errmsg += (i + 1) + "行" + jh + "井,";
                    errCount++;
                }
            }
            if (errCount > 0) {
                errmsg = errmsg.substring(0, errmsg.length() - 1);
                return R.error(60000, "导入出现错误！" + successCount + "行导入成功!    " +
                        errmsg + "行导入失败");
            } else {
                return R.success();
            }
        } catch (Exception e) {
            return R.error(60000, "导入失败！");
        } finally {
            if (workbook != null)
                workbook.close();
            inputStream.close();
        }
    }

    public static void main(String[] args) throws IOException {
        Map<String, String> channelMap = getChannel();
        Map<String, TjYjXx> map = new HashMap<>();
        File file = new File("C:\\Users\\aa\\Desktop\\加药罐\\三区.xlsx");
        XSSFWorkbook workbook = null;
        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream(file);
            workbook = new XSSFWorkbook(inputStream);
            Sheet sheet = workbook.getSheetAt(0); // 获取第一个工作表
            int rowCount = sheet.getLastRowNum() - sheet.getFirstRowNum() + 1;
            for (int i = 2; i < rowCount; i++) {
                Row row = sheet.getRow(i);
                Cell cell0 = row.getCell(0);
                String str0 = cell0.getStringCellValue();
//                \采集站1\WC56_3\HY_RGZ
//                \采集站1\明56_3\HY_RGZ
                if(!str0.matches( "\\\\\\S+\\\\\\S+\\\\\\S+")){
                    continue;
                }
                String[] strArr = str0.split("\\\\");
                if( map.get(strArr[2]) == null){
                    TjYjXx tjYjXx = new TjYjXx();
                    String jh = jhBh(strArr[2]);
                    tjYjXx.setJh(jh);
                    String channelStr = row.getCell(13).getStringCellValue();
                    tjYjXx.setIp(channelMap.get(channelStr));
                    map.put(strArr[2], tjYjXx);
                }
                TjYjXx tjYjXx = map.get(strArr[2]);
                Cell cell11 = row.getCell(11);
                String str11 = cell11.getStringCellValue();
                if(strArr[3].equals("JK_HY")){
                    if(str11.startsWith("HRU")){
                        tjYjXx.setHyregtype(4L);
                        String locStr = str11.substring(3);
                        tjYjXx.setHyloc(Long.parseLong(locStr)-1);
                    }else if(str11.startsWith("ARU")){
                        tjYjXx.setHyregtype(3L);
                        String locStr = str11.substring(3);
                        tjYjXx.setHyloc(Long.parseLong(locStr)-1);
                    }
                    tjYjXx.setHydatatype(2L);
                    tjYjXx.setHybh(1L);
                }else if(strArr[3].equals("JK_TY")){
                    if(str11.startsWith("HRU")){
                        tjYjXx.setTyregtype(4L);
                        String locStr = str11.substring(3);
                        tjYjXx.setTyloc(Long.parseLong(locStr)-1);
                    }else if(str11.startsWith("ARU")){
                        tjYjXx.setTyregtype(3L);
                        String locStr = str11.substring(3);
                        tjYjXx.setTyloc(Long.parseLong(locStr)-1);
                    }
                    tjYjXx.setTydatatype(2L);
                    tjYjXx.setTybh(1L);
                }else if(strArr[3].equals("JK_WD")){
                    if(str11.startsWith("HRU")){
                        tjYjXx.setWdregtype(4L);
                        String locStr = str11.substring(3);
                        tjYjXx.setWdloc(Long.parseLong(locStr)-1);
                    }else if(str11.startsWith("ARU")){
                        tjYjXx.setWdregtype(3L);
                        String locStr = str11.substring(3);
                        tjYjXx.setWdloc(Long.parseLong(locStr)-1);
                    }
                    tjYjXx.setWddatatype(2L);
                    tjYjXx.setWdbh(1L);
                }else if(strArr[3].equals("JK_HS1") ){
                    if(str11.startsWith("HRU")){
                        tjYjXx.setHsregtype(4L);
                        String locStr = str11.substring(3);
                        tjYjXx.setHsloc(Long.parseLong(locStr)-1);
                    }else if(str11.startsWith("ARU")){
                        tjYjXx.setHsregtype(3L);
                        String locStr = str11.substring(3);
                        tjYjXx.setHsloc(Long.parseLong(locStr)-1);
                    }
                    tjYjXx.setHsdatatype(2L);
                    tjYjXx.setHsbh(3L);
                }else if(strArr[3].equals("JK_JYGYW")){
                    if(str11.startsWith("HRU")){
                        tjYjXx.setJygywregtype(4L);
                        String locStr = str11.substring(3);
                        tjYjXx.setJygywloc(Long.parseLong(locStr)-1);
                    }else if(str11.startsWith("ARU")){
                        tjYjXx.setJygywregtype(3L);
                        String locStr = str11.substring(3);
                        tjYjXx.setJygywloc(Long.parseLong(locStr)-1);
                    }
                    tjYjXx.setJygywdatatype(2L);
                    tjYjXx.setJygywbh(1L);
                }
            }
        }catch (Exception e) {
                e.printStackTrace();
        }finally{
            if (workbook != null)
                workbook.close();
            if (inputStream != null)
                inputStream.close();
        }
        File fileNew = new File("C:\\Users\\aa\\Desktop\\加药罐\\油井点表数据导入模板.xlsx");

        InputStream isNew = new FileInputStream(fileNew);
        XSSFWorkbook workbookNew = new XSSFWorkbook(isNew);
        Sheet sheet = workbookNew.getSheetAt(0);
        System.out.println(map.size());

        int i=1;
        for(String key : map.keySet()){
            TjYjXx tjYjXx = map.get(key);
            System.out.println(tjYjXx);
            Row row = sheet.createRow(i++);
            row.createCell(0).setCellValue(tjYjXx.getJh());
            row.createCell(1).setCellValue(tjYjXx.getIp());
            row.createCell(2).setCellValue("采油管理三区");
            if(tjYjXx.getHyregtype() != null) {
                if (tjYjXx.getHyregtype() == 3) {
                    row.createCell(6).setCellValue("输入寄存器");
                } else if (tjYjXx.getHyregtype() == 4) {
                    row.createCell(6).setCellValue("保持寄存器");
                }
                row.createCell(7).setCellValue(tjYjXx.getHyloc());
                row.createCell(8).setCellValue("16位无符号数");//数据类型
                row.createCell(9).setCellValue("0.01d");//变换
            }
            if(tjYjXx.getTyregtype() != null) {
                if (tjYjXx.getTyregtype() == 3) {
                    row.createCell(10).setCellValue("输入寄存器");
                } else if (tjYjXx.getTyregtype() == 4) {
                    row.createCell(10).setCellValue("保持寄存器");
                }
                row.createCell(11).setCellValue(tjYjXx.getTyloc());
                row.createCell(12).setCellValue("16位无符号数");
                row.createCell(13).setCellValue("0.01d");
            }
            if(tjYjXx.getWdregtype() != null) {
                if (tjYjXx.getWdregtype() == 3) {
                    row.createCell(14).setCellValue("输入寄存器");
                } else if (tjYjXx.getWdregtype() == 4) {
                    row.createCell(14).setCellValue("保持寄存器");
                }
                row.createCell(15).setCellValue(tjYjXx.getWdloc());
                row.createCell(16).setCellValue("16位无符号数");
                row.createCell(17).setCellValue("0.01d");
            }
            if(tjYjXx.getHsregtype()!=null) {
                if (tjYjXx.getHsregtype() == 3) {
                    row.createCell(18).setCellValue("输入寄存器");
                } else if (tjYjXx.getHsregtype() == 4) {
                    row.createCell(18).setCellValue("保持寄存器");
                }
                row.createCell(19).setCellValue(tjYjXx.getHsloc());
                row.createCell(20).setCellValue("16位无符号数");
                row.createCell(21).setCellValue("含水率");
            }
            if(tjYjXx.getJygywregtype()!=null) {
                if (tjYjXx.getJygywregtype() == 3) {
                    row.createCell(22).setCellValue("输入寄存器");
                } else if (tjYjXx.getJygywregtype() == 4) {
                    row.createCell(22).setCellValue("保持寄存器");
                }
                row.createCell(23).setCellValue(tjYjXx.getJygywloc());
                row.createCell(24).setCellValue("16位无符号数");
                row.createCell(25).setCellValue("0.01d");
            }
        }
        FileOutputStream outputStream = new FileOutputStream("C:\\Users\\aa\\Desktop\\加药罐\\三区New.xlsx");
        workbookNew.write(outputStream);
        outputStream.close();
//        return R.success("成功");
    }

    private static String jhBh(String s) {
        String s1 = "";
        if(s.startsWith("WMN")){
            s1 = "明新" + s.substring(3);
        }else if(s.startsWith("WMC")){
            s1 = "明侧" + s.substring(3);
        }else if(s.startsWith("WM")){
            s1 = "明" + s.substring(2);
        }else if(s.startsWith("WCY")){
            s1 = "云" + s.substring(3);
        }else if(s.startsWith("WC")){
            s1 = "卫" + s.substring(2);
        }else{
            s1 = s;
        }
        if(s1.matches( ".*_.*")){
            s1 = s1.replace('_', '-');
        }
        if(s1.matches( ".*C.*")){
            s1 = s1.replaceAll("C", "侧");
        }
        return s1;
    }

    private static Map<String, String> getChannel() throws IOException {
        Map<String, String> map = new HashMap<>();
        File file = new File("C:\\Users\\aa\\Desktop\\加药罐\\三区.xlsx");
        XSSFWorkbook workbook = null;
        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream(file);
            workbook = new XSSFWorkbook(inputStream);
            Sheet sheet = workbook.getSheetAt(1); // 获取第2个工作表
            int rowCount = sheet.getLastRowNum() - sheet.getFirstRowNum() + 1;
            for (int i = 2; i < rowCount; i++) {
                try {
                    Row row = sheet.getRow(i);
                    Cell cell0 = row.getCell(0);
                    Cell cell3 = row.getCell(3);
                    String str0 = cell0.getStringCellValue();
                    String str3 = cell3.getStringCellValue();
                    map.put(str0, str3);
                }catch(Exception e){
                    e.printStackTrace();
                }
            }
            return map;
        }finally{
            if(workbook != null){
                workbook.close();
            }
            if(inputStream != null){
                inputStream.close();
            }
        }
//        return map;
    }

    public static void main2(String[] args) {
        String str = "\\采集站1\\WC56_3\\HY_RGZ";
        String str1 = "\\";
        System.out.println(str.matches("\\\\采集站1\\\\\\S+\\\\\\S+"));
        String[] strs = str.split("\\\\");
        System.out.println(strs[0]);
        System.out.println(strs[1]);
        System.out.println(strs[2]);
        System.out.println(strs[3]);
        System.out.println();
    }
}
